<template>
	<view>
		<view class="c_userinfolist">
			<view class="c_userinfolistitem">
				头像
			</view>
			<view class="c_userinfolistitem_value"  @click="upload">
				<image :src="info.avatar"  class="c_userimg"></image>
				<text class="yticon icon-you"></text>
			</view>
		</view>
		<view class="c_userinfolist">
			<view class="c_userinfolistitem">
				昵称
			</view>
			<view class="c_userinfolistitem_value">
				<input type="text" placeholder="请输入昵称" v-model="info.nickname" />
				<text class="yticon icon-you"></text>
			</view>
			
		</view>
		<!-- <view class="c_userinfolist">
			<view class="c_userinfolistitem">
				ID
			</view>
			<view class="c_userinfolistitem_value">
				<text selectable>{{info.id}}</text>
			</view>
		</view> -->
		<view class="c_userinfolist">
			<view class="c_userinfolistitem">
				邀请码
			</view>
			<view class="c_userinfolistitem_value">
				<text selectable>{{info.id}}</text>
			</view>
			
		</view>
		
		<view class="c_userinfolist real_ame" @click="$navTo('/pages/address/address')">
			<view class="c_userinfolistitem">
				地址管理
			</view>
			<view class="c_userinfolistitem_value">
				<text class="yticon icon-you"></text>
			</view>
		</view>
		
		<!-- <view class="c_userinfolist real_ame" @click="$navTo('../userservice/reaname')">
			<view class="c_userinfolistitem">
				实名认证
			</view>
			<view class="c_userinfolistitem_value">
				<text class="yticon icon-you"></text>
			</view>
		</view> -->
		
		<view class="reaname_sumbit" @click="go">确认修改</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id:'',
				info: {},
				imgs: '',
			};
		},
		onLoad(option) {
			var that = this;
			that.id = option.id;
			that.$axios('Info/member_info', "POST", 'member').then(res => {
				if (res.data.code == 200) {
					that.info = res.data.data.member;
					that.imgs = that.info.avatar;
				}
			}, (error) => {

			})
		},
		methods: {
			// 选择头像
			upload() {
				var that = this;
				uni.chooseImage({
					count: Int16Array,
					success: (res) => {
						that.info.avatar = res.tempFilePaths[0];
					}
				})
			},
			// 提交
			go() {
				var _this = this;
				var token = ""
				const value = uni.getStorageSync('token');
				if (value) {
					token = value
				}
				uni.showLoading({
					title: '提交中'
				});
				if (_this.info.avatar == _this.imgs) {
					_this.info.avatar = _this.imgs;
					_this.$axios('Info/main', "POST", 'member', _this.info).then(res => {
						uni.hideLoading();
						if (res.data.code == 200) {
							uni.showModal({
								content: '修改成功',
								showCancel: false,
								success(e) {
									uni.switchTab({
										url: '/pages/individualism/user'
									})
								}
							})
						}
					})
				} else {
					uni.uploadFile({
						url: _this.$url.state.url.upload,
						filePath: _this.info.avatar,
						name: 'a',
						header: {
							token: token
						},
						formData: {
							'file': 'a'
						},
						success: upres => {
							var data = JSON.parse(upres.data);
							if (data.code == 200) {
								_this.info.avatar = data.data.url;
								_this.$axios('Info/main', "POST", 'member', _this.info).then(res => {
									uni.hideLoading();
									var title = '';
									if (res.data.code == 200) {
										uni.showModal({
											content: '修改成功',
											showCancel: false,
											success(e) {
												uni.switchTab({
													url: '/pages/individualism/user'
												})
											}
										})
									} else {
										uni.showToast({
											title: res.data.data,
											duration: 2000,
											icon: 'none'
										});
									}

								})
							} else {
								uni.showToast({
									title: data.data,
									duration: 2000,
									icon: 'none'
								});
							}
						},
						fail: err => {
							uni.showToast({
								title: '修改失败',
								duration: 2000,
								icon: 'none'
							});
						}
					})
				}
			},
			onCancel() {

			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color:#f2f2f2;
	}

	.c_userinfolist {
		background-color: #fff;
		border-bottom: 1px $border-color-dark solid;
		display: flex;
		align-items: center;
		padding: 20upx;
	}
	.c_userinfolistitem_value{
		display: flex;
		justify-content: flex-end;
		align-items: center;
		flex: 1;
	}
	.c_userinfolistitem_value image{
		border-radius: 50%;
		height: 90upx;
		width: 90upx;
	}
	.c_userinfolistitem_value text{
		margin-left: 10upx;
	}
	.c_userinfolistitem_value input{
		text-align: right;
		flex: 1;
	}
	.real_ame{
		margin-top: 20upx;
	}
	.reaname_sumbit{
		background-color: $base-color;
		border-radius: 40upx;
		color: #fff;
		font-size: 30upx;
		line-height: 70upx;
		margin: 60upx auto;
		text-align: center;
		letter-spacing: 3px;
		width: 90%;
	}
</style>
